<?php

        set_time_limit(500);

        require_once 'simple_html_dom.php';
        require_once '../bo/News.php';


        /**
         * Description of HTMLReader
         *
         * @author Laraki
         */
        class HTMLReader {


        //Hespress.com
        public static function ExtractHespressNews($url,$categ){
            $source="hespress";
            $source_icon="icon.jpg";
            $date=date('Y-m-d H:i:s');

            $url2=$url.'/';
            $html = file_get_html($url2);
			$article_h=$html->find('div[id=article_holder]');
            $article=$html->find('div[id=article_body]');
			$a_h=$article_h[0];
            $title=$a_h->find('h1');
			$title=htmlentities($title[0]->innertext,ENT_QUOTES | ENT_IGNORE);
			$img=$a_h->find('img');
            $img=$img[0]->src;
			$contenu="";
            foreach($article[0]->find('p') as $p){
                $contenu.=htmlentities($p->innertext.'<br>',ENT_QUOTES | ENT_IGNORE);
            }
            $news=new News($url,$title,$contenu,$date,$img,$source,$source_icon,$categ);
            return $news;
        }

        //HibaPress.com
        public static function ExtractHibapressNews($url){
            $categ='general';
            $source="hibapress";
            $source_icon="icon.jpg";
            $date=date('Y-m-d H:i:s');

            $html = file_get_html($url);
            $article=$html->find('.news')[0];
            $title=htmlentities($article->find('img')[0]->title.'<br>',ENT_QUOTES | ENT_IGNORE);
            $img=$article->find('img')[0]->src;
            $contenu="";
            foreach($article->find('p') as $p){
                $contenu.=htmlentities($p->plaintext.'<br>',ENT_QUOTES | ENT_IGNORE);
            }
            $news=new News($url,$title,$contenu,$date,$img,$source,$source_icon,$categ);
            return $news;
        }

        //Menara
        public static function ExtractMenaraNews($url,$categorie){
            $source="menara";
            $source_icon="icon.jpg";
            $date=date('Y-m-d H:i:s');
            $html = file_get_html($url);
            $article=$html->find('#main')[0]->find('.content')[1];
            $title=htmlentities($article->find('#titre')[0]->innertext,ENT_QUOTES | ENT_IGNORE);
            $img=$article->find('img')[0]->src;
            $contenu="";
            foreach($article->find('p') as $p){
                $contenu.=htmlentities($p->plaintext.'<br>',ENT_QUOTES | ENT_IGNORE);
            }
            $news=new News($url,$title,$contenu,$date,$img,$source,$source_icon,$categorie);
            return $news;
        }
}

//Test
//$var=HTMLReader::ExtractHibapressNews('http://www.hibapress.com/details-7329.html');
//$var=HTMLReader::ExtractMenaraNews('http://www.menara.ma/ar/node/717740','general');
//echo $var->contenu;

?>
